package com.mycjj.android.activity;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.mycjj.android.R;
import com.mycjj.android.bean.GetSignsBaseBean.SignBean;
import com.mycjj.android.util.Preferences;
import com.mycjj.android.util.Utils;
import com.squareup.timessquare.CalendarPickerView;
import com.squareup.timessquare.CalendarPickerView.OnDateSelectedListener;
import com.squareup.timessquare.CalendarPickerView.SelectionMode;

//签到记录
public class Score_SignRecordActivity extends BaseActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_score_sign_record);
		initHeader();
		init();
	}

	private ImageView mHeaderLeftImageview;
	private Button mHeaderRightButton;
	private TextView mHeaderTitleTextView;

	private void initHeader() {
		mHeaderLeftImageview = (ImageView) findViewById(R.id.header_left_button);
		mHeaderLeftImageview.setImageResource(R.drawable.back);
		mHeaderRightButton = (Button) findViewById(R.id.header_right_button);
		mHeaderRightButton.setVisibility(View.GONE);
		mHeaderTitleTextView = (TextView) findViewById(R.id.header_title_textview);
		mHeaderTitleTextView.setText("签到记录");
		mHeaderLeftImageview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Score_SignRecordActivity.this.finish();
			}
		});
	}

	private CalendarPickerView calendar;
	private TextView mMouthTextView;
	private TextView mTv_store_name;
	private ImageView mLeftButton, mRightButton;
	private Button mSureButton;

	private Calendar mFirstDateOfMonthCal;
	private Calendar mLastDateOfMonthCal;
	private Calendar mCurrentDateCal;
	Date date = new Date();
	private String mShareDate;
	private List<SignBean> data;
	
	private TextView tv_times;
	private TextView tv_total;
	private void init() {
		Intent intent = getIntent();
		int count = 0;
		if (intent != null) {
			data = (List<SignBean>)intent.getSerializableExtra("data");
			if(data != null && !data.isEmpty()){
				count = data.size();
			}
		}
		mTv_store_name = (TextView) findViewById(R.id.tv_store_name);
		tv_times = (TextView)findViewById(R.id.tv_times);
		tv_times.setText("签到"+count+"次");
		tv_total = (TextView)findViewById(R.id.tv_total);
		//获取签到元宝数量
		String points =  Preferences.getSharedPreferences(Score_SignRecordActivity.this, "sign_score", "5");
		int sign_point = Integer.parseInt(points);
		int total = count * sign_point;
		tv_total.setText("共领取"+total+"元宝");
		calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
		calendar.setSelection(0);
		calendar.setSelectionAfterHeaderView();
		mMouthTextView = (TextView) findViewById(R.id.mouth_textview);
		mLeftButton = (ImageView) findViewById(R.id.left_button);
		mRightButton = (ImageView) findViewById(R.id.right_button);
		mLeftButton.setVisibility(View.INVISIBLE);
		mRightButton.setVisibility(View.INVISIBLE);
		mShareDate = Utils.getFormateDate(date, "yyyy-MM-dd");
		mCurrentDateCal = Calendar.getInstance();
		mCurrentDateCal.setTime(date);

		mFirstDateOfMonthCal = Calendar.getInstance();
		mFirstDateOfMonthCal.setTime(date);
		mLastDateOfMonthCal = Utils.lastDayOfMonth(date);
		calendar.initSigned(mFirstDateOfMonthCal.getTime(),
				mLastDateOfMonthCal.getTime(),data) //
				.inMode(SelectionMode.SINGLE) //
				.withSelectedDate(date);
		calendar.setOnDateSelectedListener(new OnDateSelectedListener() {

			@Override
			public void onDateUnselected(Date date) {

			}

			@Override
			public void onDateSelected(Date date) {
				Log.d("mark",
						"format:" + Utils.getFormateDate(date, "yyyy-MM-dd"));
			}
		});
		mMouthTextView.setText(mFirstDateOfMonthCal.get(Calendar.YEAR) + "年"
				+ Utils.getMonth(mFirstDateOfMonthCal.get(Calendar.MONTH) + 1)
				+ " 月");
	}

}
